
import dingTalkApi from 'dingtalk-app/dtalk/DingTalkApi';
import * as Router from 'koa-router';
import { IRouterContext } from 'koa-router';
let router = new Router();
router.prefix('/api/auth');
//钉钉免登
router.get('/login', async (ctx: IRouterContext, next: any) => {
    let authCode: string = ctx.query.code;
    let authjson: any = await dingTalkApi.login(authCode, 'jobnumber', 'mobile', 'isAdmin', 'roles', 'avatar', 'department', 'isLeaderInDepts', 'workPlace');
    console.log(authjson)
    ctx.body = authjson;
    await next();
});

//pc端签名
router.get('/getPcJsConfig', async (ctx: IRouterContext, next: any) => {
    let config = await dingTalkApi.signature('pc/' + (ctx.querystring ? `?${ctx.querystring}` : ""));
    console.log(config);
    ctx.body = config
    await next();
})

//js签名
router.get('/getJsConfig', async (ctx: IRouterContext, next: any) => {
    let config = await dingTalkApi.signature((ctx.querystring ? `?${ctx.querystring}` : ""));
    console.log(config);
    ctx.body = config
    await next();
});

export default router


